package 数组;

//遍历10行杨辉数
public class 杨辉三角 {
    public static void main(String[] args) {
        //声明初始化数组
        int [][] yanghui = new int[10][];
        for (int i = 0; i < yanghui.length; i++) {
            yanghui[i] = new int[i + 1];
            //初始化每行首末元素
            yanghui[i][0] = yanghui[i][i] = 1;
            //赋值非首末元素
            for (int j = 1; j < yanghui[i].length-1; j++) {
                yanghui[i][j] = yanghui[i - 1][j - 1] + yanghui[i - 1][j];
            }
        }
        for (int i = 0; i < yanghui.length; i++) {
            for (int j = 0; j < yanghui[i].length; j++) {
                System.out.print(yanghui[i][j] + " ");
            }
            System.out.println();
        }
    }
}
